package com.imay.live.activity.family.controller;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.imay.live.R;
import com.imay.live.activity.family.FamilyFeedActivity;
import com.imay.live.fragment.dynamics.LinearFragment;
import com.imay.live.model.FeedModel;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/9/14 0014.
 */

public class FamilyFeedController extends BaseFamilyController {

    LinearFragment linearFragment;

    @Override
    protected void initView() {
        linearFragment = LinearFragment.newInstance();
        addFragment(linearFragment);
    }

    private void addFragment(Fragment loadFragment) {
        FragmentManager fragmentManager = ((FamilyFeedActivity) activity).getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        Fragment fragment = fragmentManager.findFragmentByTag(LinearFragment.class.toString());
        if (fragment == null) {
            transaction.add(R.id.fl_family_feed_content, loadFragment, LinearFragment.class.toString());
        }
        transaction.show(loadFragment);
        transaction.commitAllowingStateLoss();
    }

    public void setFeedData(ArrayList<FeedModel> feedData) {
        linearFragment.setDatas(feedData);
        linearFragment.setRefreshFinish();
    }

    public void addFeedData(ArrayList<FeedModel> feedData) {
        linearFragment.addDatas(feedData);
        linearFragment.setLoadFinish();
    }
}
